import { Injectable } from '@angular/core'
import { I18NService } from '@core'
import { IBaseInfoColumn } from '@shared/interfaces/baseInfo'
import {
  ICardChannelVisa,
  ICardChannelMasterCard,
  ICardChannelAmericanExpress,
  EAccessMode,
  AccessModeMap,
  ICardChannelUpiExpress,
} from '@shared/interfaces/acquirer'
import { parseCurValue, numScale } from 'app/utils/helpers'

@Injectable({
  providedIn: 'root',
})
export class CardChannelDetailHelperService {
  constructor(private i18n: I18NService) {}

  getVISChannelColumns(channel: ICardChannelVisa): IBaseInfoColumn[][] {
    return [
      [
        {
          span: 8,
          label: 'chanCode',
          value: channel.chanCode,
        },
        {
          span: 8,
          label: 'accessMode',
          value: this.parseAccessMode(channel.accessMode) || channel.accessMode,
        },
        {
          span: 8,
          label: 'BIN',
          value: channel.bin,
        },
      ],
      [
        {
          span: 12,
          label: 'Institution Code in Offline System',
          value: channel.offlineInsCode,
        },
        {
          span: 12,
          label: 'Channel Institution Code in Offline System',
          value: channel.offlineChannelInsCode,
        },
      ],
      [
        {
          span: 12,
          label: 'IP',
          value: channel.lineIP,
        },
        {
          span: 12,
          label: 'Port',
          value: channel.port,
        },
      ],
      [
        {
          span: 6,
          label: 'Transaction Currency',
          value: parseCurValue(channel.currencies),
        },
        {
          span: 6,
          label: 'Transaction Fee',
          value: numScale(channel.fee, 2) + '%',
        },
        {
          span: 6,
          label: 'Channel Merchant Name',
          value: channel.chanMerName,
        },
        {
          span: 4,
          label: '操作',
          labelI18n: 'GENERAL.INFO.OPERATION',
          operate: true,
          acl: ['api.delete.toz.institution.one.channel'],
        },
      ],
    ]
  }

  getMCCChannelColumns(channel: ICardChannelMasterCard): IBaseInfoColumn[][] {
    return [
      [
        {
          span: 6,
          label: 'chanCode',
          value: channel.chanCode,
        },
        {
          span: 6,
          label: 'accessMode',
          value: this.parseAccessMode(channel.accessMode) || channel.accessMode,
        },
        {
          span: 6,
          label: 'BIN',
          value: channel.bin,
        },
        {
          span: 6,
          label: 'ICA',
          value: channel.ica,
        },
      ],
      [
        {
          span: 12,
          label: 'Institution Code in Offline System',
          value: channel.offlineInsCode,
        },
        {
          span: 12,
          label: 'Channel Institution Code in Offline System',
          value: channel.offlineChannelInsCode,
        },
      ],
      [
        {
          span: 12,
          label: 'IP',
          value: channel.lineIP,
        },
        {
          span: 12,
          label: 'Port',
          value: channel.port,
        },
      ],

      [
        {
          span: 6,
          label: 'Transaction Currency',
          value: parseCurValue(channel.currencies),
        },
        {
          span: 6,
          label: 'Transaction Fee',
          value: numScale(channel.fee, 2) + '%',
        },
        {
          span: 6,
          label: 'Channel Merchant Name',
          value: channel.chanMerName,
        },
        {
          span: 4,
          label: '操作',
          labelI18n: 'GENERAL.INFO.OPERATION',
          operate: true,
          acl: ['api.delete.toz.institution.one.channel'],
        },
      ],
    ]
  }

  getAMEChannelColumns(channel: ICardChannelAmericanExpress): IBaseInfoColumn[][] {
    return [
      [
        {
          span: 6,
          label: 'chanCode',
          value: channel.chanCode,
        },
        {
          span: 6,
          label: 'accessMode',
          value: this.parseAccessMode(channel.accessMode) || channel.accessMode,
        },
        {
          span: 6,
          label: 'AIN',
          value: channel.ain,
        },
        {
          span: 6,
          label: 'First 3 digits of S/E Number',
          value: channel.first3DigitsOfSENumber,
        },
      ],
      [
        {
          span: 6,
          label: 'Transaction Currency',
          value: parseCurValue(channel.currencies),
        },
        {
          span: 6,
          label: 'Transaction Fee',
          value: numScale(channel.fee, 2) + '%',
        },
        {
          span: 6,
          label: 'Channel Merchant Name',
          value: channel.chanMerName,
        },
        {
          span: 4,
          label: '操作',
          labelI18n: 'GENERAL.INFO.OPERATION',
          operate: true,
          acl: ['api.delete.toz.institution.one.channel'],
        },
      ],
    ]
  }

  getUPIChannelColumns(channel: ICardChannelUpiExpress): IBaseInfoColumn[][] {
    return [
      [
        {
          span: 12,
          labelI18n: 'BIZ.ACQUIRER.OTHER.CHANNEL.PAYMENT_CHANNEL',
          label: 'chanCode',
          value: channel.chanCode,
        },
        {
          span: 12,
          labelI18n: 'BIZ.ACQUIRER.CHANNEL.CARD.ACCESS_MODE',
          label: 'accessMode',
          value: this.parseAccessMode(channel.accessMode) || channel.accessMode,
        },
      ],
      [
        {
          span: 12,
          label: 'ain',
          labelI18n: 'GENERAL.INFO.CHANNEL.ACQUIRING_IIN',
          value: channel.ain,
        },
        {
          span: 12,
          labelI18n: 'GENERAL.INFO.CHANNEL.FOWARDING_IIN',
          label: 'fin',
          value: channel.fin,
        },
      ],
      [
        {
          span: 12,
          labelI18n: 'GENERAL.INFO.TRANSACTION_CURRENCY',
          label: 'currencies',
          value: parseCurValue(channel.currencies),
        },
        {
          span: 12,
          labelI18n: 'GENERAL.INFO.TRANSACTION_FEE',
          label: 'fee',
          value: numScale(channel.fee, 2) + '%',
        },
      ],
      [
        {
          span: 12,
          label: 'lineIP',
          labelI18n: 'BIZ.ACQUIRER.CHANNEL.CARD.LINE_ADDRESS_IP',
          value: channel.lineIP,
        },
        {
          span: 12,
          label: 'port',
          labelI18n: 'BIZ.ACQUIRER.CHANNEL.CARD.LINE_PORT',
          value: channel.port,
        },
      ],
      [
        {
          span: 10,
          label: 'chanMerName',
          labelI18n: 'GENERAL.INFO.CHANNEL.MERCHANT_NAME',
          value: channel.chanMerName,
        },
        {
          span: 10,
          labelI18n: 'GENERAL.INFO.REMARK',
          label: 'remark',
          value: channel.remark,
        },
        {
          span: 4,
          label: '操作',
          labelI18n: 'GENERAL.INFO.OPERATION',
          operate: true,
          acl: ['api.delete.toz.institution.one.channel'],
        },
      ],
    ]
  }
  trans(key: string, params?: Object): string {
    return this.i18n.fanyi(key, params)
  }

  parseAccessMode(accessMode: EAccessMode): string {
    return AccessModeMap[accessMode]
  }
}
